/**
* @author Ashish Gupta
* CVSSP, University of Surrey
* Copyright (c) 2010 Ashish Gupta
* All rights reserved.
*/
/**
 * 
 */
package uk.surrey.ash.ga;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.StreamTokenizer;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Scanner;

/**
 * @author Ashish
 *
 */
@SuppressWarnings("unused")
public class Dataset {
	private ArrayList<Images> images = new ArrayList<Images>();

	/**
	 * @param filename the images to set
	 * @throws IOException 
	 */
//	public void setImages(String filename) throws IOException {
//		File file = new File(filename);
//		FileReader fr = new FileReader(file);
//		BufferedReader br = new BufferedReader(fr);
//		for(;;){
//			String str = br.readLine();
//			if(str==null){
//				break;
//			}
//			else{
//				StringReader sr = new StringReader(str);
//				StreamTokenizer st = new StreamTokenizer(sr);
//				Images tempImage = new Images();
//				tempImage.setImgid(st.nextToken());
//				tempImage.setImgclass( st.nextToken());
//				images.add(tempImage);
//			}
//		}
//	}
	
	public void setImages(String filename) throws IOException{
		File file = new File(filename);
		Scanner scanner = new Scanner(file);
		try{
			while(scanner.hasNextLine()){
				processLine(scanner.nextLine());
			}
		}
		finally{
			scanner.close();
		}
	}

	/**
	 * @param nextLine
	 */
	private void processLine(String nextLine) {
		Scanner scanner = new Scanner(nextLine);
		scanner.useDelimiter(" ");
		Images tmpImage = new Images();
		tmpImage.setImgid(Integer.parseInt(scanner.next()));
		tmpImage.setImgclass(Integer.parseInt(scanner.next()));
		images.add(tmpImage);
		scanner.close();
	}

	/**
	 * @return the images
	 */
	public ArrayList<Images> getImages() {
		return images;
	}

}
